﻿<html>
<head>
<META http-equiv="refresh" content="60" />
<style>
th{
	font-size:12px;
}
td{
	font-size:12px;
}
</style>
</head>
<body>
<?php
@ $matchTime = $_GET["matchTime"];

if ($matchTime == NULL) {
	$matchTime = date('Y-m-d');
}

$config = require 'conf/config.ini.php';      //加载公用config.ini.php
$conn = mysql_connect($config["DB_HOST"], $config["DB_USER"], $config["DB_PWD"]);
mysql_select_db($config["DB_NAME"], $conn);
mysql_query("SET NAMES utf8");

$sql = "select m.matchTime,m.matchId, m.matchOptaId, m.matchName, m.homeTeam, m.visitTeam, w.userId,  w.userIp,  w.userMac, w.userInTime, w.userOutTime, ";
$sql .= "(select userId from live_user u where u.id=w.userId) userName ";
$sql .= "from live_match m, live_watch w ";
$sql .= "where";
$sql .= "	m.matchId = w.matchId ";
$sql .= "and		left(w.userInTime,10) = '" . $matchTime . "' ";
$sql .= "order by m.matchTime desc, m.matchId, w.userInTime desc";
$watchList = mysql_query($sql, $conn);

$sql = "select m.matchName, m.homeTeam, m.visitTeam, count(*) count ";
$sql .= "from live_match m, live_watch w ";
$sql .= "where";
$sql .= "	m.matchId = w.matchId ";
$sql .= "and		left(w.userInTime,10) = '" . $matchTime . "' ";
$sql .= "group by m.matchId ";
$sql .= "order by count desc";
$matchList = mysql_query($sql, $conn);
?>

<div style="float:left;width:30%; margin-right:10px;">
<table width="100%" cellspacing="0" cellpadding="2">
	<tr>
	  <th width="50px" rowspan="2">名次</th>
	  <th width="200px" rowspan="2">比赛名称</th>
	  <th width="150px">主队名称</th>
	  <th width="50px" rowspan="2">人数</th>
    </tr>
	<tr>
	  	<th>客队名称</th>
  	</tr>
<?php

$color = "";
$i = 0;
while ($match = mysql_fetch_object($matchList)) {

	if ($i++ % 2 == 0) {
		$color = "#FA5";
	} else {
		$color = "#FFFFFF";
	}
	
	echo '<tr align="center" bgcolor="' . $color . '">';
	echo '<td rowspan="2" style="font-size:24; font-weight:bold">' . $i . '</td>';
	echo '<td rowspan="2">' . $match->matchName . '</td>';
	echo '<td>' . $match->homeTeam . '</td>';
	echo '<td rowspan="2">' . $match->count . '</td>';
	echo '</tr>';
	echo '<tr align="center" bgcolor="' . $color . '">';
	echo '<td>' . $match->visitTeam . '</td>';
	echo '</tr>';
}
?>
</table>
</div>
<div style="float:left;width:65%;">
<table width="100%" cellspacing="0" cellpadding="2">
	<tr>
	  	<th width="15%">比赛时间</th>
	  	<th width="10%">比赛ID</th>
	  	<th width="20%">主队名称</th>
		<th width="15%">用户ID</th>
	  	<th width="20%">收看用户IP</th>
	  	<th width="20%">进入时间</th>
	</tr>
	<tr>
	  	<th>赛事名称</th>
		<th>比赛OPTAID</th>
	  	<th>客队名称</th>
		<th>用户名</th>
		<th>收看用户MAC</th>
		<th>退出时间</th>
	</tr>
<?php

$matchIdTemp = null;
$color = "";
$i = 0;
while ($watch = mysql_fetch_object($watchList)) {
	if ($matchIdTemp != $watch->matchId) {

		if ($i++ % 2 == 0) {
			$color = "#B5E7FF";
		} else {
			$color = "#FFFFFF";
		}

		echo '<tr align="center" bgcolor="' . $color . '">';
		echo '<td>' . $watch->matchTime . '</td>';
		echo '<td>' . $watch->matchId . '</td>';
		echo '<td>' . $watch->homeTeam . '</td>';
		echo '<td>' . $watch->userId . '</td>';
		echo '<td>' . $watch->userIp . '</td>';
		echo '<td>' . $watch->userInTime . '</td>';
		echo '</tr>';
		echo '<tr align="center" bgcolor="' . $color . '" bordercolor="#FF0000">';
		echo '<td>' . $watch->matchName . '</td>';
		echo '<td>' . $watch->matchOptaId . '</td>';
		echo '<td>' . $watch->visitTeam . '</td>';
		echo '<td style="border-bottom:1px #CEEFFF dashed">' . $watch->userName . '</td>';
		echo '<td style="border-bottom:1px #CEEFFF dashed">' . $watch->userMac . '</td>';
		echo '<td style="border-bottom:1px #CEEFFF dashed">' . $watch->userOutTime . '</td>';
		$matchIdTemp = $watch->matchId;
	} else {
		echo '<tr align="center" bgcolor="' . $color . '">';
		echo '<td></td>';
		echo '<td></td>';
		echo '<td></td>';
		echo '<td>' . $watch->userId . '</td>';
		echo '<td>' . $watch->userIp . '</td>';
		echo '<td>' . $watch->userInTime . '</td>';
		echo '</tr>';
		echo '<tr align="center" bgcolor="' . $color . '" bordercolor="#FF0000">';
		echo '<td></td>';
		echo '<td></td>';
		echo '<td></td>';
		echo '<td style="border-bottom:1px #CEEFFF dashed">' . $watch->userName . '</td>';
		echo '<td style="border-bottom:1px #CEEFFF dashed">' . $watch->userMac . '</td>';
		echo '<td style="border-bottom:1px #CEEFFF dashed">' . $watch->userOutTime . '</td>';
	}
}
?>
</table>
</div>
</body>
</html>